# /usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2022/1/11 10:19
# @Author  : lt
# @Email   : lt@163.com
# @File    : addxs_page.py
# @Software: PyCharm
from selenium.webdriver.common.by import By
from page.KHGL_page.Base_Page import BasePage
from selenium.webdriver.support.select import Select
class Add_Xs_Page(BasePage):
    # 定位线索池输入框
    xiansuochi_locator = (By.ID, 'remove')
    # 定位负责人输入框
    fuzeren_locator = (By.ID, 'owner_name')
    # 定位负责人表
    tbody_locator = (By.ID, 'd_content')
    # 定位客户来源
    laiyuan_locator = (By.ID, 'source')
    # 定位职位输入框
    zhiwei_locator = (By.ID, 'position')
    # 定位公司输入框
    gongsi_locator = (By.ID, 'name')
    # 定位联系人输入框
    person_locator = (By.ID, 'contacts_name')
    # 定位手机输入框
    mobile_locator = (By.ID, 'mobile')
    # 定位尊称输入框
    zuncheng_locator = (By.ID, 'saltname')
    # 定位邮箱输入框
    email_locator = (By.ID, 'email')
    # 定位省份输入框
    adress_locator = (
    By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(6) > td:nth-child(2) > select:nth-child(2)')
    # 定位城市输入框
    city_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(6) > td:nth-child(2) > select:nth-child(3)')
    # 定位下次联系时间输入框
    next_time_locator = (By.NAME, 'nextstep_time')
    # 定位下次联系内容输入框
    next_step_locator = (By.ID, 'nextstep')
    # 定位描述输入框
    description_locator = (By.ID, 'description')
    # 定位保存按钮输入框
    baocun_locator = (By.CSS_SELECTOR, '#form1 > table > tfoot > tr > td > input:nth-child(1)')
    # 定位添加成功
    tianjia_locator = (By.CSS_SELECTOR, 'body > div.container > div.alert.alert-success')

    # 点击放入线索池按钮
    def xiansuochi_button(self):
        self.driver.find_element(*self.xiansuochi_locator).click()
    # 点击弹框确定
        self.driver.switch_to.alert.accept()

    # 点击负责人输入框
    def fuzeren(self,fuzeren):
        self.driver.find_element(*self.fuzeren_locator).click()
    def fuzeren_tbody(self,fuzeren):
        tobdy = self.driver.find_element(*self.tbody_locator)
        trs = tobdy.find_elements(By.TAG_NAME, 'tr')
        for i in trs:
            tds = i.find_elements(By.TAG_NAME, 'td')
            if tds[1].text == fuzeren:
                tds[0].click()
                break
    # 点击负责人弹框的ok按钮
    def fuzern_ok(self):
        self.driver.find_element(By.XPATH, '/html/body/div[7]/div[3]/div/button[1]/span').click()
    # 下拉框筛选客户来源
    def kehu_laiyuan(self,laiyuan):
        Select(self.driver.find_element(*self.laiyuan_locator)).select_by_visible_text(laiyuan)
    # 输入职位
    def xs_zhiwei(self,zhiwei):
        self.driver.find_element(*self.zhiwei_locator).send_keys(zhiwei)
    # 输入公司名
    def gongsi(self,gongsi):
        self.driver.find_element(*self.gongsi_locator).send_keys(gongsi)
    # 输入联系人名
    def lianxiren_name(self,lianxiren):
        self.driver.find_element(*self.person_locator).send_keys(lianxiren)
    # 输入手机号
    def mobile_num(self,mobile):
        self.driver.find_element(*self.mobile_locator).send_keys(mobile)
    # 下拉框筛选尊称
    def kehu_zuncheng(self,zuncheng):
        Select(self.driver.find_element(*self.zuncheng_locator)).select_by_visible_text(zuncheng)
    # 输入邮箱
    def email(self,email):
        self.driver.find_element(*self.email_locator).send_keys(email)
    # 输入省份
    def shengfen_address(self,address):
        Select(self.driver.find_element(*self.adress_locator)).select_by_visible_text(address)
    # 输入城市
    def city_address(self,city):
        Select(self.driver.find_element(*self.city_locator)).select_by_visible_text(city)
    # 输入下次联系时间
    def next_lianxi_time(self,next_time):
        self.driver.find_element(*self.next_time_locator).send_keys(next_time)
    # 输入下次联系内容
    def next_lianxi_step(self,next_step):
        self.driver.find_element(*self.next_step_locator).send_keys(next_step)
    # 输入描述内容
    def description_lianxi(self,description):
        self.driver.find_element(*self.description_locator).send_keys(description)
    # 点击确定
    def queren_click(self):
        self.driver.find_element(*self.baocun_locator).click()
    # 判断是否添加成功
    def tianjia_succeful(self):
     text = self.driver.find_element(*self.tianjia_locator).text
     return text